package pwd.allen.androiddemo.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.MediaController;
import android.widget.VideoView;

import com.danikula.videocache.HttpProxyCacheServer;

import pwd.allen.androiddemo.MyApplication;
import pwd.allen.androiddemo.R;

public class VideoViewActivity extends AppCompatActivity implements View.OnClickListener {

    private VideoView videoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_view);

        videoView = findViewById(R.id.videoView);
        MediaController mediaController = new MediaController(this);
        mediaController.setPrevNextListeners(this, this);
        videoView.setMediaController(mediaController);
        String path = "https://vali-g1.cp31.ott.cibntv.net/youku/677403e64dd4171c6db66489b/030008010063D20BD80B398C6117AC80B84A60-B031-4850-A911-0953C643A5FE.mp4?sid=167678493800010007325_00_Ba59fdfd346dbe8c9f6b94075af8008f1&sign=5a1c0118397b265217141fa7cf8e9c2c&ctype=50&si=183&psid=b77e5b17b1317c42ce1df4ba900283cf41346";
        // 使用AndroidVideoCache实现视频缓存
        HttpProxyCacheServer proxy = MyApplication.getProxy(this);
        path = proxy.getProxyUrl(path);
        Log.i("mennalisha", path);
        videoView.setVideoPath(path);
        videoView.start();
    }

    @Override
    public void onClick(View v) {
        Log.i("mennalisha", v.toString());
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        videoView.stopPlayback();
    }
}
